t = int(input())
for tc in range(t):
n = int(input())
arr = list(map(int, input().split()))
a, b = arr.index(max(arr)), arr.index(min(arr))
if b < a:
a, b = b, a
print(n-max(b-a-1, a, n-1-b))
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=b;i>=a;i--)
typedef long long ll;
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
const ll inf = 1e17;
vector<ll > f[N];
ll a[N];
void solve() {
int n;
cin >> n;
int mi = 110, mn = 0;
int mip = 110, mnp = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (mi > a[i]) {
mi = a[i];
mip = i;
}
if (a[i] > mn) {
mn = a[i];
mnp = i;
}
}
int ans = min({
max(mip,mnp),
n-min(mip,mnp)+1,
mip+n-mnp+1,
mnp+n-mip+1
});
cout << ans << endl;
}
int main() {
//ios::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
ll t;
cin >> t;
//t = 1;
while (t--) {
solve();
}
return 0;
}
Count of integers | Differences of the permutations |
Doctor's Secret | Back to School |
I am Easy | Teddy and Tweety |
Partitioning binary strings | Special sets |
Smallest chosen word | Going to office |
Color the boxes | Missing numbers |
Maximum sum | 13 Reasons Why |
Friend's Relationship | Health of a person |
Divisibility | A. Movement |
Numbers in a matrix | Sequences |
Split houses | Divisible |
Three primes | Coprimes |
Cost of balloons | One String No Trouble |
Help Jarvis! | Lift queries |
Goki and his breakup | Ali and Helping innocent people |